package mybatis.config;

import com.alibaba.druid.pool.DruidDataSource;
import mybatis.studymybatis.ZhiGanMapperScanner;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author zhangzg
 * @date 2023/4/4
 */
@ComponentScan({"mybatis.service"})
@ZhiGanMapperScanner("mybatis.dao")
@Configuration
public class AppConfig {


    @Bean
    public DataSource getDataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver"); //驱动
        dataSource.setUrl("jdbc:mysql://120.46.188.178:3306/dev_kc_core_consign?useUnicode=true&characterEncoding=UTF-8");//连接数据库URL
        dataSource.setUsername("zhangzg");//mysql登陆用户名
        dataSource.setPassword("MNMI_89UJnfgg");//mysql登陆密码
        dataSource.setMaxActive(100);//连接池最大连接数
        dataSource.setMinIdle(20);//连接池最小连接数
        dataSource.setMaxWait(1000);//连接池超时时间
        return dataSource;
    }

    /*@Bean
    public TransactionManager getTrans(){
        DataSourceTransactionManager trans =  new DataSourceTransactionManager();
        //设置数据源
        trans.setDataSource(this.getDataSource());
        return trans;
    }*/

    /*@Bean
    public FactoryBean getFactory(){
        SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
        //设置数据源
        factory.setDataSource(this.getDataSource());
        return factory;
    }*/



}
